package com.situ.controller.orders;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.customer.CstCustomer;
import com.situ.entity.might.SysMight;
import com.situ.entity.orders.Ordersl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.orders.OrdersService;
import com.situ.entity.orders.Orders;
import com.situ.util.*;

import java.util.List;

/**
 * Orders的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class OrdersController {

	/** OrdersService服务 */
	@Autowired
	private OrdersService ordersService;
	
	/**
	 * 查询所有Orders数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/Orders/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(Orders value) {

		return ResponseData.ok().putDataValue("list",ordersService.find(value));
	}
	
	/**
	 * 通过id查询Orders数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Orders/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",ordersService.findOne(id));
	}
	
	/**
	 * 插入Orders属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Orders/save")
	public ResponseData save(Orders value) {
		return ResponseData.ok().putDataValue("obj", ordersService.saveNotNull(value));
	}
	
	/**
	 * 更新Orders属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Orders/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(Orders value) {
		return ResponseData.ok().putDataValue("obj",ordersService.updateNotNullById(value));
	}

	/**
	 * 通过id删除Orders数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Orders/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",ordersService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/Orders/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(Orders value,
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @RequestParam(defaultValue = "5",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<Orders> list = ordersService.querybylikecustomer(value);
        PageInfo pageInfo = new PageInfo<Orders>(list, 5);

        return ResponseData.ok()
        // .putDataValue("list", list)
        .putDataValue("pageInfo",pageInfo);
        }



    @RequestMapping(value = "/Orders/queryPage2", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage2(Ordersl value) {
        List list = ordersService.find2(value);
String ff="22";
        return ResponseData.ok().putDataValue("list", list);
    }
}
